home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 2000 July: Mac OS SDK / Dev.CD Jul 00 SDK2.toast / Development Kits / Hardware / Mac OS USB DDK / Mac OS USB DDK 1.4.1 / Examples / USBSampleStorageDriver / StorageClassDriver / StorageDriverHeader.c < prev    next >
Encoding:
C/C++ Source or Header  |  2000-04-25  |  4.5 KB  |  143 lines  |  [TEXT/CWIE]

  1. /*
  2.     File:        StorageDriverHeader.c
  3.  
  4.     Contains:    All globally exported functions and structures
  5.  
  6.     Version:    2.0
  7.  
  8.     Copyright:    © 1998-1999 by Apple Computer, Inc., all rights reserved.
  9.  
  10. */
  11.  
  12.  
  13.  
  14. #include <Types.h>
  15. #include <Devices.h>
  16. #include <DriverServices.h>
  17. #include <USB.h>
  18.  
  19. #include "StorageClassDriver.h"
  20. #include "USB_Version.h"
  21. #include "StorageDeviceConfiguration.h"
  22.  
  23. //------------------------------------------------------
  24. //
  25. // Protos
  26. //
  27. //------------------------------------------------------
  28. static OSStatus StorageDriverValidateHW(USBDeviceRef device, USBDeviceDescriptor *desc);
  29. static OSStatus StorageDriverInitDevice(USBDeviceRef device, USBDeviceDescriptorPtr pDesc, UInt32 busPowerAvailable);
  30. static OSStatus StorageDriverInitInterface( UInt32 interfaceNum, USBInterfaceDescriptor *interfaceDesc, USBDeviceDescriptor *deviceDesc, USBDeviceRef device);
  31. static OSStatus StorageDriverFinalize(USBDeviceRef device, USBDeviceDescriptorPtr desc );
  32. static OSStatus StorageDriverNotifyProc(UInt32     notification, void *pointer, UInt32 refcon);
  33.  
  34. //------------------------------------------------------
  35. //
  36. //    This is the driver description structure that the expert looks for first.
  37. //  If it's here, the information within is used to match the driver
  38. //  to the device whose descriptor was passed to the expert.
  39. //    Information in this block is also used by the expert when an
  40. //  entry is created in the Name Registry.
  41. //
  42. //------------------------------------------------------
  43. USBDriverDescription    TheUSBDriverDescription = 
  44. {
  45.     // Signature info
  46.     kTheUSBDriverDescriptionSignature,            // 'usbd'
  47.     kInitialUSBDriverDescriptor,                // 0
  48.     
  49.     // Device Info
  50.     kDeviceVendorID,                            // USB Vendor ID
  51.     kDeviceProductID,                            // USB Product ID.
  52.     0,                                            // Release Number of Device
  53.     0,                                            // Protocol Info.
  54.     
  55.     // Interface Info            
  56.     0,                                            // Configuration Value
  57.     0,                                            // Interface Number
  58.     kDeviceClass,                                // Interface Class
  59.     kDeviceSubClass,                             // Interface SubClass
  60.     0,                                            // Interface Protocol
  61.     
  62.     // Driver Info    
  63.     kDriverNameString,                            // Driver name for Name Registry
  64.     kDeviceClass,                                // Device Class  (from SampleStorageDeviceID.h)
  65.     kDeviceSubClass,                            // Device Subclass
  66.     kStorageHexMajorVers, kStorageHexMinorVers, kStorageReleaseStage, kStorageCurrentRelease,        // version of driver = 0.0d0
  67.     
  68.     // Driver Loading Info
  69.     kUSBDoNotMatchGenericDevice                    // Flags, Do not allow for generic match
  70. };
  71.     
  72. USBClassDriverPluginDispatchTable TheClassDriverPluginDispatchTable =
  73. {
  74.     kClassDriverPluginVersion,                    // Version of this structure
  75.     StorageDriverValidateHW,                    // Hardware Validation Procedure
  76.     StorageDriverInitDevice,                    // Initialization Procedure
  77.     StorageDriverInitInterface,                    // Interface Initialization Procedure
  78.     StorageDriverFinalize,                        // Finalization Procedure
  79.     StorageDriverNotifyProc,                    // Driver Notification Procedure
  80. };
  81.  
  82. // Hardware Validation
  83. // Called upon load by Expert
  84. OSStatus StorageDriverValidateHW ( USBDeviceRef device, USBDeviceDescriptorPtr pDesc )
  85. {
  86. #pragma unused ( device )
  87.  
  88.     if (IsThisASupportedProtocol( pDesc->protocol ) == false )
  89.     {
  90.         // This device speaks a protocol we do not understand, return back an error
  91.         // so USB will try to find a better suited driver.
  92.         return kUSBIncorrectTypeErr;
  93.     }
  94.  
  95.     return noErr;
  96. }
  97.  
  98.  
  99. // Initialization function
  100. // Called upon load by Expert
  101. OSStatus StorageDriverInitDevice ( USBDeviceRef device, USBDeviceDescriptorPtr pDesc, UInt32 busPowerAvailable )
  102. {
  103.     busPowerAvailable = 0;
  104.     StorageDriverEntry(device, pDesc, NULL );
  105.     
  106.     return noErr;
  107. }
  108.  
  109. // StorageDriverInitInterface function
  110. // Called to initialize driver for an individual interface - either by expert or
  111. // internally by driver
  112. OSStatus StorageDriverInitInterface( UInt32 interfaceNum, USBInterfaceDescriptor *interfaceDesc, 
  113.                                         USBDeviceDescriptor *deviceDesc, USBDeviceRef device )
  114. {
  115. #pragma unused ( interfaceNum )
  116.     if (IsThisASupportedProtocol( interfaceDesc->interfaceProtocol ) == false )
  117.     {
  118.         // This device speaks a protocol we do not understand, return back an error
  119.         // so USB will try to find a better suited driver.
  120.         return kUSBIncorrectTypeErr;
  121.     }
  122.  
  123.     StorageDriverEntry(device, deviceDesc, interfaceDesc );
  124.     return noErr;
  125. }
  126.  
  127. // Termination function
  128. // Called by Expert when driver is being shut down
  129. OSStatus StorageDriverFinalize( USBDeviceRef device, USBDeviceDescriptorPtr desc )
  130. {
  131. #pragma unused( device, desc )
  132.  
  133.     StorageClassDriverFinalize();
  134.  
  135.     return noErr;
  136. }
  137.  
  138. OSStatus StorageDriverNotifyProc( UInt32 notification, void* pointer, UInt32 refcon)
  139. {
  140.     return StorageClassDriverNotifyProc(notification, pointer, refcon);
  141. }
  142.  
  143.